package com.longxi.tianjintianbao.ui.adapter.multitype.inventory;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.greedao.entity.Inventory;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class InventoryViewBinder extends ItemViewBinder<Inventory, InventoryViewBinder.ViewHolder> {
    OnClickListener listener;

    public InventoryViewBinder(OnClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_inventory, parent, false);
        return new ViewHolder(root);
    }

    

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Inventory inventory) {
        holder.tvReceiptNumber.setText("单据编号:" + inventory.getNumber());
        holder.tvState.setText(inventory.getState());

        holder.mLlBtn.setOnClickListener(v -> listener.onClick(holder.getAdapterPosition()));

        holder.btnDelete.setOnClickListener(v -> listener.onDelete(holder.getAdapterPosition()));
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView tvReceiptNumber;
        TextView tvState;
        ImageView btnDelete;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            tvReceiptNumber = itemView.findViewById(R.id.tvReceiptNumber);
            tvState = itemView.findViewById(R.id.tvState);
            btnDelete = itemView.findViewById(R.id.btnDelete);
        }
    }

    public interface OnClickListener {
        void onClick(int position);
        void onDelete(int position);
    }

}
